//上传手持身份证照片
//a: upload   b:upload_aft  c:  upImg   d:infoLogoForm
var certImgHand, certImgPositive,certImgNegative;
var token = localStorage.getItem('tok');
function uploadDocuments(a,b,c,d,m){
    a.bind('click',function () {
        c.trigger('click');
    });
    c.on('change',function () {
        $.ajax({
            url:$host+ "/api/upload/imgsIc",
            type: 'POST',
            cache: false,
            data: new FormData(d[0]),
            processData: false,
            contentType: false,
            dataType:"json",
            beforeSend: function(){
            },
            success : function(res) {
                if(res.data.address){
                    var {data:{address}} = res;
                    a.hide();
                    b.show();
                    b.css('background','url('+address+')no-repeat center/100% 100%');
                    switch (m) {
                        case 1:
                            certImgHand = address;
                            break;
                        case 2:
                            certImgPositive = address;
                            break;
                        case 3:
                            certImgNegative = address;
                            break;
                        default:
                            break;
                    }
                }
            }
        });
    });
}

uploadDocuments($('.upload'),$('.upload_aft'),$('.upImg'),$('.infoLogoForm'),1);
uploadDocuments($('.upload-front'),$('.upload_aft-front'),$('.upImg-front'),$('.infoLogoForm-front'),2);
uploadDocuments($('.upload-back'),$('.upload_aft-back'),$('.upImg-back'),$('.infoLogoForm-back'),3);

//点击取消
//e:quxiao_btn    f:upload_aft  g:upload
var cancel = (e,f,g)=>{
    e.click(function(e){
        e.stopPropagation();
        e.preventDefault();
        f.css('background','#d2d2d2');
        f.hide();
        g.show();
    })
};

cancel($('.quxiao_btn'),$('.upload_aft'),$('.upload'));
cancel($('.quxiao_btn-front'),$('.upload_aft-front'),$('.upload-front'));
cancel($('.quxiao_btn-back'),$('.upload_aft-back'),$('.upload-back'));

//确认上传
$('.btn').click(function () {
        $.ajax({
            type: "POST",
            url: $host + '/api/app/cert/addCertInfo',
            async: true,
            dataType: 'json',
            data: {
                "token":token,
                "certImgHand":certImgHand,
                "certImgPositive":certImgPositive,
                "certImgNegative":certImgNegative
            },
            success: function (result) {
                console.log(result);
                if(result.status===900000){
                    window.location.href="shenhejd.html?token="+token
                }
            },
            error: function () {

            }
        })
    }
)
//点击返回
$('.sczjfh').click(function(){
    window.location.href="shenhejd.html?token="+token;
})

